package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.AreaCodeRsp;
import com.ruoyi.business.mapper.BAreaCodeMapper;
import com.ruoyi.business.service.IBAreaCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
@EnableAsync
public class BAreaCodeServiceImpl implements IBAreaCodeService {

    @Autowired
    BAreaCodeMapper bAreaCodeMapper;

    @Override
    public List<AreaCodeRsp> getTree() {

        List<AreaCodeRsp> byParentId = bAreaCodeMapper.getByParentId(0L);
        getTreea(byParentId);
        return byParentId;
    }

    private void getTreea(List<AreaCodeRsp> byParentId){
        for (int i =0;i<byParentId.size();i++){
            List<AreaCodeRsp> level2 = bAreaCodeMapper.getByParentId(byParentId.get(i).getId());
            for (int j = 0;j<level2.size();j++){
                List<AreaCodeRsp> level3 = bAreaCodeMapper.getByParentId(level2.get(j).getId());
//                for (int k = 0;k<level3.size();k++){
//                    List<AreaCodeRsp> level4 = bAreaCodeMapper.getByParentId(level3.get(k).getId());
//                    level3.get(k).setChildren(level4);
//                }
                level2.get(j).setChildren(level3);
            }
            byParentId.get(i).setChildren(level2);
        }
    }
}
